package com.aisino.chapter03;

import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.concurrent.CompletableFuture;

public class TestMainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        // 设置状态栏和导航栏的padding
//        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
//            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
//            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
//            return insets;
//        });
        // 启动应用后开启一个异步任务变更文字
        CompletableFuture.runAsync(() -> {
            try {
                Log.i("gct", "onCreate: 休眠开始,3s");
                Thread.sleep(3000);
                Log.i("gct", "onCreate: 休眠结束");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            // 修改UI 此方法可以把逻辑放到主线程执行
            runOnUiThread(() -> {
                Log.i("gct", "onCreate: ui 会被修改");
                TextView textView = findViewById(R.id.tv_hello);
                textView.setText("第三章控件开始");
                textView.setTextSize(30);
                textView.setTextColor(Color.GREEN);// 设置文字颜色 6位 八位 16进制
                textView.setBackgroundColor(Color.RED);
            });
        });
    }
}